﻿namespace WMS6.Web.Inventory
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.InventoryMgtServiceRef;

    public class BatchTransfer : BasePage
    {
        protected Button btnGoBack;
        protected Button btnRefresh;
        protected Button btnReplace;
        protected Button btnSave;
        protected DropDownList ddlTransferType;
        protected HtmlForm F5069;
        protected GridView gvTransferDetail;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnFromOwner;
        protected HtmlInputHidden hdnIndex;
        protected HtmlHead Head1;
        protected HtmlImage img;
        protected HtmlImage imgTime;
        protected Label lblBatchTransfer;
        protected Label lblMsg;
        protected Label lblToOwnerID;
        protected Label lblTransferDate;
        protected Label lblTransFerID;
        protected Label lblTransType;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtReplace;
        protected TextBox txtToOwnerID;
        protected TextBox txtTransferDate;
        protected TextBox txtTransFerID;

        public void BindDataInvLotLocLpnList(InvLotLocLpnQueryEntity invLotLocLpnQueryEntity)
        {
            DataSet ds = new DataSet();
            ds = InventoryMgtServiceClientProxy.GetInstance().GetInvLotLocLpnByQueryEntity(invLotLocLpnQueryEntity);
            base.DataGridViewState = ds;
            base.BindData2GridView(this.gvTransferDetail, ds);
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("BatchTransferQuery.aspx", false);
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtToOwnerID.Text))
            {
                this.lblMsg.Text = "请输入货主!";
            }
            else if (string.IsNullOrEmpty(this.txtTransferDate.Text))
            {
                this.lblMsg.Text = "请输入转移日期!";
            }
            else
            {
                TransferInfo transferInfo = new TransferInfo {
                    Status = "NEW",
                    FromOwnerID = this.hdnFromOwner.Value,
                    ToOwnerID = this.txtToOwnerID.Text.Trim(),
                    TransferDate = DateTime.Parse(this.txtTransferDate.Text.Trim()),
                    TransferType = this.ddlTransferType.SelectedValue,
                    GenIsInCharges = "N",
                    GenOtCharges = "N",
                    IsActive = "Y",
                    CreatedBy = base.UserInfo.UserID,
                    TransferDetailInfos = new List<TransferDetailInfo>()
                };
                if (this.gvTransferDetail.Rows.Count <= 0)
                {
                    this.lblMsg.Text = "未找到合适的数据源进行批量保存!";
                }
                else
                {
                    for (int i = 0; this.gvTransferDetail.Rows.Count > i; i++)
                    {
                        if (((CheckBox) this.gvTransferDetail.Rows[i].Cells[1].Controls[1]).Checked)
                        {
                            DateTime CS00001;
                            TransferDetailInfo transferDetailInfo = new TransferDetailInfo {
                                LineID = (i + 1) * 10,
                                FromOwnerID = this.gvTransferDetail.DataKeys[i]["OWNER_ID"].ToString()
                            };
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtSkuID")) != null)
                            {
                                transferDetailInfo.FromSkuID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtSkuID")).ToolTip;
                                transferDetailInfo.ToSkuID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtSkuID")).Text;
                            }
                            else
                            {
                                transferDetailInfo.FromSkuID = this.gvTransferDetail.DataKeys[i]["SKU_ID"].ToString();
                                transferDetailInfo.ToSkuID = this.gvTransferDetail.DataKeys[i]["SKU_ID"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLoc")) != null)
                            {
                                transferDetailInfo.FromLoc = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLoc")).ToolTip;
                                transferDetailInfo.ToLoc = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLoc")).Text;
                            }
                            else
                            {
                                transferDetailInfo.FromLoc = this.gvTransferDetail.DataKeys[i]["LOC"].ToString();
                                transferDetailInfo.ToLoc = this.gvTransferDetail.DataKeys[i]["LOC"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLot")) != null)
                            {
                                transferDetailInfo.ToLot = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLot")).Text;
                                transferDetailInfo.FromLot = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLot")).ToolTip;
                            }
                            else
                            {
                                transferDetailInfo.ToLot = this.gvTransferDetail.DataKeys[i]["LOT"].ToString();
                                transferDetailInfo.FromLot = this.gvTransferDetail.DataKeys[i]["LOT"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLpn")) != null)
                            {
                                transferDetailInfo.ToLpnID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLpn")).Text;
                                transferDetailInfo.FromLpnID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLpn")).ToolTip;
                            }
                            else
                            {
                                transferDetailInfo.ToLpnID = this.gvTransferDetail.DataKeys[i]["LPN_ID"].ToString();
                                transferDetailInfo.FromLpnID = this.gvTransferDetail.DataKeys[i]["LPN_ID"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtQty")) != null)
                            {
                                transferDetailInfo.FromQty = decimal.Parse(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtQty")).ToolTip);
                                if (!(string.IsNullOrEmpty(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtQty")).Text) || (decimal.Parse(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtQty")).Text) < 0M)))
                                {
                                    transferDetailInfo.ToQty = decimal.Parse(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtQty")).Text);
                                }
                                else
                                {
                                    this.lblMsg.Text = "输入数量不能小于0!";
                                    break;
                                }
                                transferDetailInfo.Udf1 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtQty")).ToolTip;
                            }
                            else
                            {
                                transferDetailInfo.FromQty = Convert.ToDecimal(this.gvTransferDetail.DataKeys[i]["Qty"]);
                                transferDetailInfo.ToQty = Convert.ToDecimal(this.gvTransferDetail.DataKeys[i]["Qty"]);
                                transferDetailInfo.Udf1 = this.gvTransferDetail.DataKeys[i]["Qty"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtPackID")) != null)
                            {
                                transferDetailInfo.ToPackID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtPackID")).Text;
                                transferDetailInfo.FromPackID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtPackID")).ToolTip;
                            }
                            else
                            {
                                transferDetailInfo.ToPackID = this.gvTransferDetail.DataKeys[i]["PACK_ID"].ToString();
                                transferDetailInfo.FromPackID = this.gvTransferDetail.DataKeys[i]["PACK_ID"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtUomID")) != null)
                            {
                                transferDetailInfo.ToUomID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtUomID")).ToolTip;
                                transferDetailInfo.FromUomID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtUomID")).ToolTip;
                            }
                            else
                            {
                                transferDetailInfo.ToUomID = this.gvTransferDetail.DataKeys[i]["UOM_ID"].ToString();
                                transferDetailInfo.FromUomID = this.gvTransferDetail.DataKeys[i]["UOM_ID"].ToString();
                            }
                            transferDetailInfo.ToOwnerID = this.txtToOwnerID.Text;
                            transferDetailInfo.Status = "NEW";
                            ReceiptLotInfo transferLot = new ReceiptLotInfo();
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr01")) != null)
                            {
                                transferLot.LotAttr01 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr01")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr01 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR01"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr02")) != null)
                            {
                                transferLot.LotAttr02 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr02")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr02 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR02"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr03")) != null)
                            {
                                transferLot.LotAttr03 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr03")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr03 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR03"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr04")) != null)
                            {
                                transferLot.LotAttr04 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr04")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr04 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR04"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr05")) != null)
                            {
                                transferLot.LotAttr05 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr05")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr05 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR05"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr06")) != null)
                            {
                                transferLot.LotAttr06 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr06")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr06 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR06"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr07")) != null)
                            {
                                transferLot.LotAttr07 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr07")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr07 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR07"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr08")) != null)
                            {
                                transferLot.LotAttr08 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr08")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr08 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR08"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr09")) != null)
                            {
                                transferLot.LotAttr09 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr09")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr09 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR09"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr10")) != null)
                            {
                                transferLot.LotAttr10 = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtLotAttr10")).Text;
                            }
                            else
                            {
                                transferLot.LotAttr10 = this.gvTransferDetail.DataKeys[i]["LOT_ATTR10"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtReceiptDate")) != null)
                            {
                                transferLot.ReceiptDate = string.IsNullOrEmpty(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtReceiptDate")).Text) ? (CS00001 = new DateTime()) : DateTime.Parse(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtReceiptDate")).Text);
                            }
                            else
                            {
                                transferLot.ReceiptDate = string.IsNullOrEmpty(this.gvTransferDetail.DataKeys[i]["RECEIPT_DATE"].ToString()) ? (CS00001 = new DateTime()) : DateTime.Parse(this.gvTransferDetail.DataKeys[i]["RECEIPT_DATE"].ToString());
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtExternalLot")) != null)
                            {
                                transferLot.ExternalLot = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtExternalLot")).Text;
                            }
                            else
                            {
                                transferLot.ExternalLot = this.gvTransferDetail.DataKeys[i]["EXTERNAL_LOT"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtVendorID")) != null)
                            {
                                transferLot.VendorID = ((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtVendorID")).Text;
                            }
                            else
                            {
                                transferLot.VendorID = this.gvTransferDetail.DataKeys[i]["VENDOR_ID"].ToString();
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtProduceDate")) != null)
                            {
                                transferLot.ProduceDate = string.IsNullOrEmpty(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtProduceDate")).Text) ? (CS00001 = new DateTime()) : DateTime.Parse(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtProduceDate")).Text);
                            }
                            else
                            {
                                transferLot.ProduceDate = string.IsNullOrEmpty(this.gvTransferDetail.DataKeys[i]["PRODUCE_DATE"].ToString()) ? (CS00001 = new DateTime()) : DateTime.Parse(this.gvTransferDetail.DataKeys[i]["PRODUCE_DATE"].ToString());
                            }
                            if (((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtProduceDate")) != null)
                            {
                                transferLot.ExpiryDate = string.IsNullOrEmpty(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtExpiryDate")).Text) ? (CS00001 = new DateTime()) : DateTime.Parse(((TextBox) this.gvTransferDetail.Rows[i].FindControl("txtExpiryDate")).Text);
                            }
                            else
                            {
                                transferLot.ExpiryDate = string.IsNullOrEmpty(this.gvTransferDetail.DataKeys[i]["EXPIRY_DATE"].ToString()) ? (CS00001 = new DateTime()) : DateTime.Parse(this.gvTransferDetail.DataKeys[i]["EXPIRY_DATE"].ToString());
                            }
                            transferDetailInfo.TransferLotInfo = transferLot;
                            transferDetailInfo.TransferDate = DateTime.Now;
                            transferDetailInfo.CreatedBy = base.UserInfo.UserID;
                            transferDetailInfo.UpdatedBy = base.UserInfo.UserID;
                            transferInfo.TransferDetailInfos.Add(transferDetailInfo);
                        }
                    }
                    try
                    {
                        string strtemp = InventoryMgtServiceClientProxy.GetInstance().BatchInsertInvTransfer(transferInfo);
                        this.txtTransFerID.Text = strtemp;
                        this.lblMsg.Text = strtemp + " 批量生成库存转移成功!";
                        this.btnSave.Enabled = false;
                        this.btnReplace.Enabled = false;
                    }
                    catch (Exception ex)
                    {
                        this.lblMsg.Text = "批量转移失败！" + ex.Message;
                    }
                }
            }
        }

        private InvLotLocLpnQueryEntity GetInvLotLocLpnQueryEntity()
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                return (base.PageQueryEntityViewState as InvLotLocLpnQueryEntity);
            }
            return (base.PageQueryEntitySession as InvLotLocLpnQueryEntity);
        }

        protected void gvTransferDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F5069", this.gvTransferDetail);
        }

        protected void gvTransferDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                int index = 2;
                if (((RadioButton) e.Row.FindControl("rbtnSku")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnSku")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLoc")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLoc")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLot")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLot")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLpn")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLpn")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnPackID")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnPackID")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnUomID")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnUomID")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnQty")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnQty")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnExternalLot")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnExternalLot")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnReceiptDate")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnReceiptDate")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnVendorID")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnVendorID")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr01")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr01")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr02")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr02")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr03")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr03")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr04")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr04")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr05")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr05")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr06")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr06")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr07")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr07")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr08")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr08")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr09")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr09")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnLotAttr10")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnLotAttr10")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnProduceDate")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnProduceDate")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
                if (((RadioButton) e.Row.FindControl("rbtnExpiryDate")) != null)
                {
                    ((RadioButton) e.Row.FindControl("rbtnExpiryDate")).Attributes.Add("onclick", "Setindex(" + index + ")");
                    index++;
                }
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
            }
        }

        protected void gvTransferDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                InvLotLocLpnQueryEntity invLotLocLpnQueryEntity = this.GetInvLotLocLpnQueryEntity();
                invLotLocLpnQueryEntity.SortField = e.SortExpression;
                if (invLotLocLpnQueryEntity.SortDirection == "ASC")
                {
                    invLotLocLpnQueryEntity.SortDirection = "DESC";
                }
                else if (invLotLocLpnQueryEntity.SortDirection == "DESC")
                {
                    invLotLocLpnQueryEntity.SortDirection = "ASC";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            this.txtTransferDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            base.BindData2DDLBySysCode(this.ddlTransferType, "TransferType");
            this.hdnFromOwner.Value = base.Request.QueryString["fromOwnerID"];
            this.txtToOwnerID.Text = base.Request.QueryString["fromOwnerID"];
            InvLotLocLpnQueryEntity invLotLocLpnQueryEntity = new InvLotLocLpnQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    invLotLocLpnQueryEntity.OwnerID = this.PreviousPage.OwnerID;
                    invLotLocLpnQueryEntity.SkuID = this.PreviousPage.SkuID;
                    invLotLocLpnQueryEntity.SkuDescr = this.PreviousPage.SkuDescr;
                    invLotLocLpnQueryEntity.SkuClass = this.PreviousPage.SkuClassID;
                    invLotLocLpnQueryEntity.Loc = this.PreviousPage.Loaction;
                    invLotLocLpnQueryEntity.Lot = this.PreviousPage.LotAttributeID;
                    invLotLocLpnQueryEntity.LpnID = this.PreviousPage.Lpn;
                    invLotLocLpnQueryEntity.LotAttr01 = this.PreviousPage.LotAttribute01;
                    invLotLocLpnQueryEntity.LotAttr02 = this.PreviousPage.LotAttribute02;
                    invLotLocLpnQueryEntity.LotAttr03 = this.PreviousPage.LotAttribute03;
                    invLotLocLpnQueryEntity.LotAttr04 = this.PreviousPage.LotAttribute04;
                    invLotLocLpnQueryEntity.LotAttr05 = this.PreviousPage.LotAttribute05;
                    invLotLocLpnQueryEntity.LotAttr06 = this.PreviousPage.LotAttribute06;
                    invLotLocLpnQueryEntity.LotAttr07 = this.PreviousPage.LotAttribute07;
                    invLotLocLpnQueryEntity.LotAttr08 = this.PreviousPage.LotAttribute08;
                    invLotLocLpnQueryEntity.LotAttr09 = this.PreviousPage.LotAttribute09;
                    invLotLocLpnQueryEntity.LotAttr10 = this.PreviousPage.LotAttribute10;
                    invLotLocLpnQueryEntity.ProduceDate = this.PreviousPage.ProductDate;
                    invLotLocLpnQueryEntity.ExpiryDate = this.PreviousPage.ExpiryDate;
                    invLotLocLpnQueryEntity.ExternalLot = this.PreviousPage.ExternalLot;
                    invLotLocLpnQueryEntity.ReceiptDate = this.PreviousPage.ReceiptDate;
                    invLotLocLpnQueryEntity.VendorID = this.PreviousPage.VendorID;
                    invLotLocLpnQueryEntity.Qty = " >0";
                }
                else
                {
                    invLotLocLpnQueryEntity.OwnerID = "";
                    invLotLocLpnQueryEntity.SkuID = "";
                    invLotLocLpnQueryEntity.SkuDescr = "";
                    invLotLocLpnQueryEntity.SkuClass = "";
                    invLotLocLpnQueryEntity.Loc = "";
                    invLotLocLpnQueryEntity.Lot = "";
                    invLotLocLpnQueryEntity.LpnID = "";
                    invLotLocLpnQueryEntity.LotAttr01 = "";
                    invLotLocLpnQueryEntity.LotAttr02 = "";
                    invLotLocLpnQueryEntity.LotAttr03 = "";
                    invLotLocLpnQueryEntity.LotAttr04 = "";
                    invLotLocLpnQueryEntity.LotAttr05 = "";
                    invLotLocLpnQueryEntity.LotAttr06 = "";
                    invLotLocLpnQueryEntity.LotAttr07 = "";
                    invLotLocLpnQueryEntity.LotAttr08 = "";
                    invLotLocLpnQueryEntity.LotAttr09 = "";
                    invLotLocLpnQueryEntity.LotAttr10 = "";
                    invLotLocLpnQueryEntity.ProduceDate = "";
                    invLotLocLpnQueryEntity.ExpiryDate = "";
                    invLotLocLpnQueryEntity.ExternalLot = "";
                    invLotLocLpnQueryEntity.ReceiptDate = "";
                    invLotLocLpnQueryEntity.VendorID = "";
                    invLotLocLpnQueryEntity.Qty = " >0";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            invLotLocLpnQueryEntity.IsGetAll = false;
            invLotLocLpnQueryEntity.CurrentPage = "0";
            invLotLocLpnQueryEntity.PageSize = this.gvTransferDetail.PageSize.ToString();
            invLotLocLpnQueryEntity.SortField = "Lot";
            invLotLocLpnQueryEntity.SortDirection = "DESC";
            this.SetInvLotLocLpnQueryEntity(invLotLocLpnQueryEntity);
            this.BindDataInvLotLocLpnList(invLotLocLpnQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
            this.lblMsg.Text = "";
        }

        private void SetInvLotLocLpnQueryEntity(InvLotLocLpnQueryEntity invLotLocLpnQueryEntity)
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                base.PageQueryEntityViewState = invLotLocLpnQueryEntity;
            }
            else
            {
                base.PageQueryEntitySession = invLotLocLpnQueryEntity;
            }
        }

        public BatchTransferQuery PreviousPage
        {
            get
            {
                return (BatchTransferQuery) base.PreviousPage;
            }
        }
    }
}

